package 第一题;

public class HomeWork4 implements Runnable{
    private int sum;  //1加到100总和
    private int num;  //当前是第几个线程

    @Override
    synchronized public void run() {
        num = Integer.valueOf(Thread.currentThread().getName());
        for (int i = num * 10 - 9; i <= num * 10; i++) {
            sum += i;
        }
        if (num == 10) {
            System.out.println(sum);
        }

    }

    public static void main(String[] args) {
        HomeWork4 runnable = new HomeWork4();
        for (int i = 1; i <= 10; i++) {
            Thread thread = new Thread(runnable, String.valueOf(i));
            thread.start();
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
